package demo02.Day2test;

import java.util.ArrayList;

/*创建三个学生对象存入ArrayList集合中。
A：遍历集合遍历输出。
B：求出年龄最大的学生，然后将该学生的姓名变为：小猪佩奇。*/
public class student02 {
    public static void main(String[] args) {
        ArrayList<Student>list=new ArrayList<>();
        Student stu1=new Student("张三",12,"男");
        Student stu2=new Student("张四",18,"男");
        Student stu3=new Student("张五",14,"女");
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);
        int max=list.get(0).getAge();
        for (int i = 0; i < list.size(); i++) {
            Student student=list.get(i);
            if(student.getAge()>max){
                max=student.getAge();
            }
        }
        System.out.println(max);

        for (int i = 0; i < list.size(); i++) {
            Student stu=new Student();
            if(stu.getAge()==max){
                stu.setName("小猪佩奇");
            }

        }

    }
}
